<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>SQLAlchemy映射构建 | 课程简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C02-Database/SQLAlchemyOperations.html" />
    
    
    <link rel="prev" href="../C02-Database/ORM.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.3"
        data-chapter-title="SQLAlchemy映射构建"
        data-filepath="C02-Database/SQLAlchemyMapping.md"
        data-basepath=".."
        data-revision="Mon May 27 2019 03:35:45 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Introduction/index.html">
            
                
                    <a href="../C01-Introduction/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目介绍
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Introduction/AboutToutiaoWebVM.html">
            
                
                    <a href="../C01-Introduction/AboutToutiaoWebVM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        ToutiaoWeb虚拟机使用说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Introduction/PycharmRemoteDevelop.html">
            
                
                    <a href="../C01-Introduction/PycharmRemoteDevelop.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Pycharm远程开发
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Introduction/AboutProject.html">
            
                
                    <a href="../C01-Introduction/AboutProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        产品与开发
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Database/index.html">
            
                
                    <a href="../C02-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Database/DatabaseDesign.html">
            
                
                    <a href="../C02-Database/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Database/ORM.html">
            
                
                    <a href="../C02-Database/ORM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        理解ORM
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.3" data-path="C02-Database/SQLAlchemyMapping.html">
            
                
                    <a href="../C02-Database/SQLAlchemyMapping.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        SQLAlchemy映射构建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Database/SQLAlchemyOperations.html">
            
                
                    <a href="../C02-Database/SQLAlchemyOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        SQLAlchemy操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Database/DatabaseTheory.html">
            
                
                    <a href="../C02-Database/DatabaseTheory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        数据库理论
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Database/DistributedID.html">
            
                
                    <a href="../C02-Database/DistributedID.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        分布式ID
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Database/DatabaseOptimize.html">
            
                
                    <a href="../C02-Database/DatabaseOptimize.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        数据库优化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Database/Redis.html">
            
                
                    <a href="../C02-Database/Redis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        Redis
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Gitflow/index.html">
            
                
                    <a href="../C03-Gitflow/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Git工作流
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Gitflow/Gitflow.html">
            
                
                    <a href="../C03-Gitflow/Gitflow.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Gitflow
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Gitflow/AboutGit.html">
            
                
                    <a href="../C03-Gitflow/AboutGit.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Git总结
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Gitflow/ProjectDirectory.html">
            
                
                    <a href="../C03-Gitflow/ProjectDirectory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        工程目录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Gitflow/DebugMethod.html">
            
                
                    <a href="../C03-Gitflow/DebugMethod.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        调试方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-JWT/index.html">
            
                
                    <a href="../C04-JWT/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        JWT
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-JWT/JWT.html">
            
                
                    <a href="../C04-JWT/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        JWT &amp; JWS &amp; JWE
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-JWT/PythonLib.html">
            
                
                    <a href="../C04-JWT/PythonLib.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        PythonLib
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-JWT/Implement.html">
            
                
                    <a href="../C04-JWT/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        实施方案
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-JWT/Forbbiden.html">
            
                
                    <a href="../C04-JWT/Forbbiden.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        禁用问题
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-OSS/index.html">
            
                
                    <a href="../C05-OSS/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        对象存储
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-OSS/Qiniu.html">
            
                
                    <a href="../C05-OSS/Qiniu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        七牛云存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-OSS/CDN.html">
            
                
                    <a href="../C05-OSS/CDN.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        CDN
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Cache/index.html">
            
                
                    <a href="../C06-Cache/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        缓存
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Cache/CacheArchitecture.html">
            
                
                    <a href="../C06-Cache/CacheArchitecture.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        缓存的架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Cache/CacheData.html">
            
                
                    <a href="../C06-Cache/CacheData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存的数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Cache/CacheTTLAndEviction.html">
            
                
                    <a href="../C06-Cache/CacheTTLAndEviction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        缓存的有效期与淘汰策略
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="C06-Cache/CachePatterns.html">
            
                
                    <a href="../C06-Cache/CachePatterns.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        缓存模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="C06-Cache/CacheProblems.html">
            
                
                    <a href="../C06-Cache/CacheProblems.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        缓存问题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="C06-Cache/ProjectCacheAndStorageDesign.html">
            
                
                    <a href="../C06-Cache/ProjectCacheAndStorageDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        项目缓存与Redis持久存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="C06-Cache/ProjectCacheImplement.html">
            
                
                    <a href="../C06-Cache/ProjectCacheImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        项目缓存实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="C06-Cache/ProjectRedisStorageImplement.html">
            
                
                    <a href="../C06-Cache/ProjectRedisStorageImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        项目Redis持久存储实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-APScheduler/index.html">
            
                
                    <a href="../C07-APScheduler/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        APScheduler
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="C07-APScheduler/APSchedulerTutorial.html">
            
                
                    <a href="../C07-APScheduler/APSchedulerTutorial.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        APScheduler使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="C07-APScheduler/FixStatistics.html">
            
                
                    <a href="../C07-APScheduler/FixStatistics.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        定时修正统计数据
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-RPC/index.html">
            
                
                    <a href="../C08-RPC/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        RPC
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="C08-RPC/AboutRPC.html">
            
                
                    <a href="../C08-RPC/AboutRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        RPC简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="C08-RPC/gRPC.html">
            
                
                    <a href="../C08-RPC/gRPC.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        gRPC
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="C08-RPC/ProtocolBuffers.html">
            
                
                    <a href="../C08-RPC/ProtocolBuffers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        Protocol Buffers
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="C08-RPC/RecoSysIDL.html">
            
                
                    <a href="../C08-RPC/RecoSysIDL.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        推荐系统接口定义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="C08-RPC/Server.html">
            
                
                    <a href="../C08-RPC/Server.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        服务端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="C08-RPC/Client.html">
            
                
                    <a href="../C08-RPC/Client.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        客户端
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="C08-RPC/ToutiaoAPIViewImplement.html">
            
                
                    <a href="../C08-RPC/ToutiaoAPIViewImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        头条首页新闻推荐接口编写
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-IM/index.html">
            
                
                    <a href="../C09-IM/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        即时通信
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-IM/AboutIM.html">
            
                
                    <a href="../C09-IM/AboutIM.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        即时通信简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-IM/WebSocket.html">
            
                
                    <a href="../C09-IM/WebSocket.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        WebSocket
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="C09-IM/SocketIO.html">
            
                
                    <a href="../C09-IM/SocketIO.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.3.</b>
                        
                        Socket.IO
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="C09-IM/Chat.html">
            
                
                    <a href="../C09-IM/Chat.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.4.</b>
                        
                        头条聊天服务实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="C09-IM/MessagePush.html">
            
                
                    <a href="../C09-IM/MessagePush.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.5.</b>
                        
                        头条在线消息推送实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Elasticsearch/index.html">
            
                
                    <a href="../C10-Elasticsearch/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Elasticsearch
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="C10-Elasticsearch/Introduction.html">
            
                
                    <a href="../C10-Elasticsearch/Introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        简介与原理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="C10-Elasticsearch/ConceptAndCluster.html">
            
                
                    <a href="../C10-Elasticsearch/ConceptAndCluster.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        概念与集群
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="C10-Elasticsearch/AnalysisIK.html">
            
                
                    <a href="../C10-Elasticsearch/AnalysisIK.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.3.</b>
                        
                        IK中文分析器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="C10-Elasticsearch/IndexAndType.html">
            
                
                    <a href="../C10-Elasticsearch/IndexAndType.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.4.</b>
                        
                        索引与类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="C10-Elasticsearch/Document.html">
            
                
                    <a href="../C10-Elasticsearch/Document.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.5.</b>
                        
                        文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="C10-Elasticsearch/Logstash.html">
            
                
                    <a href="../C10-Elasticsearch/Logstash.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.6.</b>
                        
                        Logstash导入数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.7" data-path="C10-Elasticsearch/Query.html">
            
                
                    <a href="../C10-Elasticsearch/Query.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.7.</b>
                        
                        查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.8" data-path="C10-Elasticsearch/ToutiaoSearchImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSearchImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.8.</b>
                        
                        头条全文检索实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.9" data-path="C10-Elasticsearch/Suggest.html">
            
                
                    <a href="../C10-Elasticsearch/Suggest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.9.</b>
                        
                        suggest查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.10" data-path="C10-Elasticsearch/ToutiaoSuggestImplement.html">
            
                
                    <a href="../C10-Elasticsearch/ToutiaoSuggestImplement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.10.</b>
                        
                        头条suggest查询实现
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="C11-Unittest.html">
            
                
                    <a href="../C11-Unittest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        单元测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="C12-Deployment/index.html">
            
                
                    <a href="../C12-Deployment/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        部署相关
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="C12-Deployment/Gunicorn.html">
            
                
                    <a href="../C12-Deployment/Gunicorn.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        Gunicorn
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="C12-Deployment/Supervisor.html">
            
                
                    <a href="../C12-Deployment/Supervisor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        Supervisor
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="sqlalchemy&#x6620;&#x5C04;&#x6784;&#x5EFA;">SQLAlchemy&#x6620;&#x5C04;&#x6784;&#x5EFA;</h1>
<h2 id="1-&#x7B80;&#x4ECB;">1 &#x7B80;&#x4ECB;</h2>
<p><strong>SQLAlchemy</strong>&#x662F;Python&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x4E0B;&#x7684;&#x4E00;&#x6B3E;&#x5F00;&#x6E90;&#x8F6F;&#x4EF6;&#x3002;&#x63D0;&#x4F9B;&#x4E86;SQL&#x5DE5;&#x5177;&#x5305;&#x53CA;&#x5BF9;&#x8C61;&#x5173;&#x7CFB;&#x6620;&#x5C04;&#xFF08;ORM&#xFF09;&#x5DE5;&#x5177;&#xFF0C;&#x4F7F;&#x7528;MIT&#x8BB8;&#x53EF;&#x8BC1;&#x53D1;&#x884C;&#x3002;</p>
<p>SQLAlchemy&#x201C;&#x91C7;&#x7528;&#x7B80;&#x5355;&#x7684;Python&#x8BED;&#x8A00;&#xFF0C;&#x4E3A;&#x9AD8;&#x6548;&#x548C;&#x9AD8;&#x6027;&#x80FD;&#x7684;&#x6570;&#x636E;&#x5E93;&#x8BBF;&#x95EE;&#x8BBE;&#x8BA1;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x5B8C;&#x6574;&#x7684;&#x4F01;&#x4E1A;&#x7EA7;&#x6301;&#x4E45;&#x6A21;&#x578B;&#x201D;&#x3002;</p>
<p>SQLAlchemy&#x9996;&#x6B21;&#x53D1;&#x884C;&#x4E8E;2006&#x5E74;2&#x6708;&#xFF0C;&#x5E76;&#x8FC5;&#x901F;&#x5730;&#x5728;Python&#x793E;&#x533A;&#x4E2D;&#x6700;&#x5E7F;&#x6CDB;&#x4F7F;&#x7528;&#x7684;ORM&#x5DE5;&#x5177;&#x4E4B;&#x4E00;&#xFF0C;&#x4E0D;&#x4E9A;&#x4E8E;Django&#x7684;ORM&#x6846;&#x67B6;&#x3002;</p>
<p><strong>Flask-SQLAlchemy</strong>&#x662F;&#x5728;Flask&#x6846;&#x67B6;&#x7684;&#x4E00;&#x4E2A;&#x6269;&#x5C55;&#xFF0C;&#x5176;&#x5BF9;<strong>SQLAlchemy</strong>&#x8FDB;&#x884C;&#x4E86;&#x5C01;&#x88C5;&#xFF0C;&#x76EE;&#x7684;&#x4E8E;&#x7B80;&#x5316;&#x5728; Flask &#x4E2D; SQLAlchemy &#x7684; &#x4F7F;&#x7528;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x6709;&#x7528;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x548C;&#x989D;&#x5916;&#x7684;&#x52A9;&#x624B;&#x6765;&#x66F4;&#x7B80;&#x5355;&#x5730;&#x5B8C;&#x6210;&#x65E5;&#x5E38;&#x4EFB;&#x52A1;&#x3002;</p>
<h2 id="2-&#x5B89;&#x88C5;">2 &#x5B89;&#x88C5;</h2>
<p>&#x5B89;&#x88C5;Flask-SQLAlchemy</p>
<pre><code class="lang-shell">pip install flask-sqlalchemy
</code></pre>
<p>&#x5982;&#x679C;&#x4F7F;&#x7528;&#x7684;&#x662F;MySQL&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5B89;&#x88C5;MySQL&#x7684;Python&#x5BA2;&#x6237;&#x7AEF;&#x5E93;</p>
<pre><code class="lang-python">pip install mysqlclient
</code></pre>
<h2 id="3-&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x8BBE;&#x7F6E;">3 &#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x8BBE;&#x7F6E;</h2>
<p>&#x5728;Flask&#x4E2D;&#x4F7F;&#x7528;Flask-SQLAlchemy&#x9700;&#x8981;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x4E3B;&#x8981;&#x914D;&#x7F6E;&#x4EE5;&#x4E0B;&#x51E0;&#x9879;&#xFF1A;</p>
<ul>
<li><p><code>SQLALCHEMY_DATABASE_URI</code> &#x6570;&#x636E;&#x5E93;&#x7684;&#x8FDE;&#x63A5;&#x4FE1;&#x606F;</p>
<ul>
<li><p>Postgres:</p>
<pre><code>postgresql://user:password@localhost/mydatabase
</code></pre></li>
<li><p>MySQL:</p>
<pre><code>mysql://user:password@localhost/mydatabase
</code></pre></li>
<li><p>Oracle:</p>
<pre><code>oracle://user:password@127.0.0.1:1521/sidname
</code></pre></li>
<li><p>SQLite &#xFF08;&#x6CE8;&#x610F;&#x5F00;&#x5934;&#x7684;&#x56DB;&#x4E2A;&#x659C;&#x7EBF;&#xFF09;:</p>
<pre><code>sqlite:////absolute/path/to/foo.db
</code></pre></li>
</ul>
</li>
<li><p><code>SQLALCHEMY_TRACK_MODIFICATIONS</code> &#x5728;Flask&#x4E2D;&#x662F;&#x5426;&#x8FFD;&#x8E2A;&#x6570;&#x636E;&#x4FEE;&#x6539;</p>
</li>
<li><p><code>SQLALCHEMY_ECHO</code> &#x663E;&#x793A;&#x751F;&#x6210;&#x7684;SQL&#x8BED;&#x53E5;&#xFF0C;&#x53EF;&#x7528;&#x4E8E;&#x8C03;&#x8BD5;</p>
</li>
</ul>
<p>&#x8FD9;&#x4E9B;&#x914D;&#x7F6E;&#x53C2;&#x6570;&#x9700;&#x8981;&#x653E;&#x5728;Flask&#x7684;&#x5E94;&#x7528;&#x914D;&#x7F6E;&#xFF08;<code>app.config</code>&#xFF09;&#x4E2D;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask

app = Flask(__name__)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Config</span><span class="hljs-params">(object)</span>:</span>
    SQLALCHEMY_DATABASE_URI = <span class="hljs-string">&apos;mysql://root:mysql@127.0.0.1:3306/toutiao&apos;</span>
    SQLALCHEMY_TRACK_MODIFICATIONS = <span class="hljs-keyword">False</span>
    SQLALCHEMY_ECHO = <span class="hljs-keyword">True</span>

app.config.from_object(Config)
</code></pre>
<p>&#x5176;&#x4ED6;&#x914D;&#x7F6E;&#x53C2;&#x8003;&#x5982;&#x4E0B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x540D;&#x5B57;</th>
<th style="text-align:left">&#x5907;&#x6CE8;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">SQLALCHEMY_DATABASE_URI</td>
<td style="text-align:left">&#x7528;&#x4E8E;&#x8FDE;&#x63A5;&#x7684;&#x6570;&#x636E;&#x5E93; URI &#x3002;&#x4F8B;&#x5982;:sqlite:////tmp/test.dbmysql://username:password@server/db</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_BINDS</td>
<td style="text-align:left">&#x4E00;&#x4E2A;&#x6620;&#x5C04; binds &#x5230;&#x8FDE;&#x63A5; URI &#x7684;&#x5B57;&#x5178;&#x3002;&#x66F4;&#x591A; binds &#x7684;&#x4FE1;&#x606F;&#x89C1;<a href="http://docs.jinkan.org/docs/flask-sqlalchemy/binds.html#binds" target="_blank"><em>&#x7528; Binds &#x64CD;&#x4F5C;&#x591A;&#x4E2A;&#x6570;&#x636E;&#x5E93;</em></a>&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_ECHO</td>
<td style="text-align:left">&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E3A;Ture&#xFF0C; SQLAlchemy &#x4F1A;&#x8BB0;&#x5F55;&#x6240;&#x6709; &#x53D1;&#x7ED9; stderr &#x7684;&#x8BED;&#x53E5;&#xFF0C;&#x8FD9;&#x5BF9;&#x8C03;&#x8BD5;&#x6709;&#x7528;&#x3002;(&#x6253;&#x5370;sql&#x8BED;&#x53E5;)</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_RECORD_QUERIES</td>
<td style="text-align:left">&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x663E;&#x5F0F;&#x5730;&#x7981;&#x7528;&#x6216;&#x542F;&#x7528;&#x67E5;&#x8BE2;&#x8BB0;&#x5F55;&#x3002;&#x67E5;&#x8BE2;&#x8BB0;&#x5F55; &#x5728;&#x8C03;&#x8BD5;&#x6216;&#x6D4B;&#x8BD5;&#x6A21;&#x5F0F;&#x81EA;&#x52A8;&#x542F;&#x7528;&#x3002;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#x89C1;get_debug_queries()&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_NATIVE_UNICODE</td>
<td style="text-align:left">&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x663E;&#x5F0F;&#x7981;&#x7528;&#x539F;&#x751F; unicode &#x652F;&#x6301;&#x3002;&#x5F53;&#x4F7F;&#x7528; &#x4E0D;&#x5408;&#x9002;&#x7684;&#x6307;&#x5B9A;&#x65E0;&#x7F16;&#x7801;&#x7684;&#x6570;&#x636E;&#x5E93;&#x9ED8;&#x8BA4;&#x503C;&#x65F6;&#xFF0C;&#x8FD9;&#x5BF9;&#x4E8E; &#x4E00;&#x4E9B;&#x6570;&#x636E;&#x5E93;&#x9002;&#x914D;&#x5668;&#x662F;&#x5FC5;&#x987B;&#x7684;&#xFF08;&#x6BD4;&#x5982; Ubuntu &#x4E0A; &#x67D0;&#x4E9B;&#x7248;&#x672C;&#x7684; PostgreSQL &#xFF09;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_POOL_SIZE</td>
<td style="text-align:left">&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x6C60;&#x7684;&#x5927;&#x5C0F;&#x3002;&#x9ED8;&#x8BA4;&#x662F;&#x5F15;&#x64CE;&#x9ED8;&#x8BA4;&#x503C;&#xFF08;&#x901A;&#x5E38; &#x662F; 5 &#xFF09;</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_POOL_TIMEOUT</td>
<td style="text-align:left">&#x8BBE;&#x5B9A;&#x8FDE;&#x63A5;&#x6C60;&#x7684;&#x8FDE;&#x63A5;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x3002;&#x9ED8;&#x8BA4;&#x662F; 10 &#x3002;</td>
</tr>
<tr>
<td style="text-align:left">SQLALCHEMY_POOL_RECYCLE</td>
<td style="text-align:left">&#x591A;&#x5C11;&#x79D2;&#x540E;&#x81EA;&#x52A8;&#x56DE;&#x6536;&#x8FDE;&#x63A5;&#x3002;&#x8FD9;&#x5BF9; MySQL &#x662F;&#x5FC5;&#x8981;&#x7684;&#xFF0C; &#x5B83;&#x9ED8;&#x8BA4;&#x79FB;&#x9664;&#x95F2;&#x7F6E;&#x591A;&#x4E8E; 8 &#x5C0F;&#x65F6;&#x7684;&#x8FDE;&#x63A5;&#x3002;&#x6CE8;&#x610F;&#x5982;&#x679C; &#x4F7F;&#x7528;&#x4E86; MySQL &#xFF0C; Flask-SQLALchemy &#x81EA;&#x52A8;&#x8BBE;&#x5B9A; &#x8FD9;&#x4E2A;&#x503C;&#x4E3A; 2 &#x5C0F;&#x65F6;&#x3002;</td>
</tr>
</tbody>
</table>
<h2 id="4-&#x6A21;&#x578B;&#x7C7B;&#x5B57;&#x6BB5;&#x4E0E;&#x9009;&#x9879;">4 &#x6A21;&#x578B;&#x7C7B;&#x5B57;&#x6BB5;&#x4E0E;&#x9009;&#x9879;</h2>
<h4 id="&#x5B57;&#x6BB5;&#x7C7B;&#x578B;">&#x5B57;&#x6BB5;&#x7C7B;&#x578B;</h4>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7C7B;&#x578B;&#x540D;</th>
<th style="text-align:left">python&#x4E2D;&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Integer</td>
<td style="text-align:left">int</td>
<td style="text-align:left">&#x666E;&#x901A;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;32&#x4F4D;</td>
</tr>
<tr>
<td style="text-align:left">SmallInteger</td>
<td style="text-align:left">int</td>
<td style="text-align:left">&#x53D6;&#x503C;&#x8303;&#x56F4;&#x5C0F;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;16&#x4F4D;</td>
</tr>
<tr>
<td style="text-align:left">BigInteger</td>
<td style="text-align:left">int&#x6216;long</td>
<td style="text-align:left">&#x4E0D;&#x9650;&#x5236;&#x7CBE;&#x5EA6;&#x7684;&#x6574;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">Float</td>
<td style="text-align:left">float</td>
<td style="text-align:left">&#x6D6E;&#x70B9;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">Numeric</td>
<td style="text-align:left">decimal.Decimal</td>
<td style="text-align:left">&#x666E;&#x901A;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;32&#x4F4D;</td>
</tr>
<tr>
<td style="text-align:left">String</td>
<td style="text-align:left">str</td>
<td style="text-align:left">&#x53D8;&#x957F;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td style="text-align:left">Text</td>
<td style="text-align:left">str</td>
<td style="text-align:left">&#x53D8;&#x957F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5BF9;&#x8F83;&#x957F;&#x6216;&#x4E0D;&#x9650;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x505A;&#x4E86;&#x4F18;&#x5316;</td>
</tr>
<tr>
<td style="text-align:left">Unicode</td>
<td style="text-align:left">unicode</td>
<td style="text-align:left">&#x53D8;&#x957F;Unicode&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td style="text-align:left">UnicodeText</td>
<td style="text-align:left">unicode</td>
<td style="text-align:left">&#x53D8;&#x957F;Unicode&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5BF9;&#x8F83;&#x957F;&#x6216;&#x4E0D;&#x9650;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x505A;&#x4E86;&#x4F18;&#x5316;</td>
</tr>
<tr>
<td style="text-align:left">Boolean</td>
<td style="text-align:left">bool</td>
<td style="text-align:left">&#x5E03;&#x5C14;&#x503C;</td>
</tr>
<tr>
<td style="text-align:left">Date</td>
<td style="text-align:left">datetime.date</td>
<td style="text-align:left">&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:left">Time</td>
<td style="text-align:left">datetime.datetime</td>
<td style="text-align:left">&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:left">LargeBinary</td>
<td style="text-align:left">str</td>
<td style="text-align:left">&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;</td>
</tr>
</tbody>
</table>
<h4 id="&#x5217;&#x9009;&#x9879;">&#x5217;&#x9009;&#x9879;</h4>
<table>
<thead>
<tr>
<th style="text-align:left">&#x9009;&#x9879;&#x540D;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">primary_key</td>
<td style="text-align:left">&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4EE3;&#x8868;&#x8868;&#x7684;&#x4E3B;&#x952E;</td>
</tr>
<tr>
<td style="text-align:left">unique</td>
<td style="text-align:left">&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4EE3;&#x8868;&#x8FD9;&#x5217;&#x4E0D;&#x5141;&#x8BB8;&#x51FA;&#x73B0;&#x91CD;&#x590D;&#x7684;&#x503C;</td>
</tr>
<tr>
<td style="text-align:left">index</td>
<td style="text-align:left">&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4E3A;&#x8FD9;&#x5217;&#x521B;&#x5EFA;&#x7D22;&#x5F15;&#xFF0C;&#x63D0;&#x9AD8;&#x67E5;&#x8BE2;&#x6548;&#x7387;</td>
</tr>
<tr>
<td style="text-align:left">nullable</td>
<td style="text-align:left">&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x5141;&#x8BB8;&#x6709;&#x7A7A;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x4E3A;False&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x6709;&#x7A7A;&#x503C;</td>
</tr>
<tr>
<td style="text-align:left">default</td>
<td style="text-align:left">&#x4E3A;&#x8FD9;&#x5217;&#x5B9A;&#x4E49;&#x9ED8;&#x8BA4;&#x503C;</td>
</tr>
</tbody>
</table>
<h4 id="&#x5173;&#x7CFB;&#x9009;&#x9879;">&#x5173;&#x7CFB;&#x9009;&#x9879;</h4>
<table>
<thead>
<tr>
<th style="text-align:left">&#x9009;&#x9879;&#x540D;</th>
<th style="text-align:left">&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">backref</td>
<td style="text-align:left">&#x5728;&#x5173;&#x7CFB;&#x7684;&#x53E6;&#x4E00;&#x6A21;&#x578B;&#x4E2D;&#x6DFB;&#x52A0;&#x53CD;&#x5411;&#x5F15;&#x7528;</td>
</tr>
<tr>
<td style="text-align:left">primary join</td>
<td style="text-align:left">&#x660E;&#x786E;&#x6307;&#x5B9A;&#x4E24;&#x4E2A;&#x6A21;&#x578B;&#x4E4B;&#x95F4;&#x4F7F;&#x7528;&#x7684;&#x8054;&#x7ED3;&#x6761;&#x4EF6;</td>
</tr>
<tr>
<td style="text-align:left">uselist</td>
<td style="text-align:left">&#x5982;&#x679C;&#x4E3A;False&#xFF0C;&#x4E0D;&#x4F7F;&#x7528;&#x5217;&#x8868;&#xFF0C;&#x800C;&#x4F7F;&#x7528;&#x6807;&#x91CF;&#x503C;</td>
</tr>
<tr>
<td style="text-align:left">order_by</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x5173;&#x7CFB;&#x4E2D;&#x8BB0;&#x5F55;&#x7684;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;</td>
</tr>
<tr>
<td style="text-align:left">secondary</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x591A;&#x5BF9;&#x591A;&#x5173;&#x7CFB;&#x4E2D;&#x5173;&#x7CFB;&#x8868;&#x7684;&#x540D;&#x5B57;</td>
</tr>
<tr>
<td style="text-align:left">secondary join</td>
<td style="text-align:left">&#x5728;SQLAlchemy&#x4E2D;&#x65E0;&#x6CD5;&#x81EA;&#x884C;&#x51B3;&#x5B9A;&#x65F6;&#xFF0C;&#x6307;&#x5B9A;&#x591A;&#x5BF9;&#x591A;&#x5173;&#x7CFB;&#x4E2D;&#x7684;&#x4E8C;&#x7EA7;&#x8054;&#x7ED3;&#x6761;&#x4EF6;</td>
</tr>
</tbody>
</table>
<h2 id="5-&#x6784;&#x5EFA;&#x6A21;&#x578B;&#x7C7B;&#x6620;&#x5C04;">5 &#x6784;&#x5EFA;&#x6A21;&#x578B;&#x7C7B;&#x6620;&#x5C04;</h2>
<p>&#x4F8B;&#x7528;&#x865A;&#x62DF;&#x673A;&#x4E2D;&#x5DF2;&#x6709;&#x7684;&#x5934;&#x6761;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6784;&#x5EFA;&#x6A21;&#x578B;&#x7C7B;&#x6620;&#x5C04;&#xFF0C;&#x4EE5;&#x4E0B;&#x9762;&#x4E09;&#x5F20;&#x8868;&#x4E3A;&#x4F8B;</p>
<pre><code class="lang-sql"><span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`user_basic`</span> (
  <span class="hljs-string">`user_id`</span> <span class="hljs-built_in">bigint</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>,
  <span class="hljs-string">`account`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x8D26;&#x53F7;&apos;</span>,
  <span class="hljs-string">`email`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x90AE;&#x7BB1;&apos;</span>,
  <span class="hljs-string">`status`</span> tinyint(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;1&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x72B6;&#x6001;&#xFF0C;&#x662F;&#x5426;&#x53EF;&#x7528;&#xFF0C;0-&#x4E0D;&#x53EF;&#x7528;&#xFF0C;1-&#x53EF;&#x7528;&apos;</span>,
  <span class="hljs-string">`mobile`</span> <span class="hljs-built_in">char</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&apos;</span>,
  <span class="hljs-string">`password`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">93</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x5BC6;&#x7801;&apos;</span>,
  <span class="hljs-string">`user_name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x6635;&#x79F0;&apos;</span>,
  <span class="hljs-string">`profile_photo`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">128</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x5934;&#x50CF;&apos;</span>,
  <span class="hljs-string">`last_login`</span> datetime <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x6700;&#x540E;&#x767B;&#x5F55;&#x65F6;&#x95F4;&apos;</span>,
  <span class="hljs-string">`is_media`</span> tinyint(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x662F;&#x5426;&#x662F;&#x81EA;&#x5A92;&#x4F53;&#xFF0C;0-&#x4E0D;&#x662F;&#xFF0C;1-&#x662F;&apos;</span>,
  <span class="hljs-string">`is_verified`</span> tinyint(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x662F;&#x5426;&#x5B9E;&#x540D;&#x8BA4;&#x8BC1;&#xFF0C;0-&#x4E0D;&#x662F;&#xFF0C;1-&#x662F;&apos;</span>,
  <span class="hljs-string">`introduction`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">50</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7B80;&#x4ECB;&apos;</span>,
  <span class="hljs-string">`certificate`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">30</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x8BA4;&#x8BC1;&apos;</span>,
  <span class="hljs-string">`article_count`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x53D1;&#x6587;&#x7AE0;&#x6570;&apos;</span>,
  <span class="hljs-string">`following_count`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x5173;&#x6CE8;&#x7684;&#x4EBA;&#x6570;&apos;</span>,
  <span class="hljs-string">`fans_count`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x88AB;&#x5173;&#x6CE8;&#x7684;&#x4EBA;&#x6570;&apos;</span>,
  <span class="hljs-string">`like_count`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7D2F;&#x8BA1;&#x70B9;&#x8D5E;&#x4EBA;&#x6570;&apos;</span>,
  <span class="hljs-string">`read_count`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7D2F;&#x8BA1;&#x9605;&#x8BFB;&#x4EBA;&#x6570;&apos;</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`user_id`</span>),
  <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">KEY</span> <span class="hljs-string">`mobile`</span> (<span class="hljs-string">`mobile`</span>),
  <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">KEY</span> <span class="hljs-string">`user_name`</span> (<span class="hljs-string">`user_name`</span>)
) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8 <span class="hljs-keyword">COMMENT</span>=<span class="hljs-string">&apos;&#x7528;&#x6237;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x8868;&apos;</span>;</span>

<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`user_profile`</span> (
  <span class="hljs-string">`user_id`</span> <span class="hljs-built_in">bigint</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>,
  <span class="hljs-string">`gender`</span> tinyint(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x6027;&#x522B;&#xFF0C;0-&#x7537;&#xFF0C;1-&#x5973;&apos;</span>,
  <span class="hljs-string">`birthday`</span> <span class="hljs-built_in">date</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x751F;&#x65E5;&apos;</span>,
  <span class="hljs-string">`real_name`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x771F;&#x5B9E;&#x59D3;&#x540D;&apos;</span>,
  <span class="hljs-string">`id_number`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&apos;</span>,
  <span class="hljs-string">`id_card_front`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">128</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x6B63;&#x9762;&apos;</span>,
  <span class="hljs-string">`id_card_back`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">128</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x80CC;&#x9762;&apos;</span>,
  <span class="hljs-string">`id_card_handheld`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">128</span>) <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x624B;&#x6301;&#x8EAB;&#x4EFD;&#x8BC1;&apos;</span>,
  <span class="hljs-string">`create_time`</span> datetime <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&apos;</span>,
  <span class="hljs-string">`update_time`</span> datetime <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">ON</span> <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&apos;</span>,
  <span class="hljs-string">`register_media_time`</span> datetime <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x6CE8;&#x518C;&#x81EA;&#x5A92;&#x4F53;&#x65F6;&#x95F4;&apos;</span>,
  <span class="hljs-string">`area`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x5730;&#x533A;&apos;</span>,
  <span class="hljs-string">`company`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x516C;&#x53F8;&apos;</span>,
  <span class="hljs-string">`career`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x804C;&#x4E1A;&apos;</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`user_id`</span>)
) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8 <span class="hljs-keyword">COMMENT</span>=<span class="hljs-string">&apos;&#x7528;&#x6237;&#x8D44;&#x6599;&#x8868;&apos;</span>;</span>

<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`user_relation`</span> (
  <span class="hljs-string">`relation_id`</span> <span class="hljs-built_in">bigint</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x4E3B;&#x952E;id&apos;</span>,
  <span class="hljs-string">`user_id`</span> <span class="hljs-built_in">bigint</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>,
  <span class="hljs-string">`target_user_id`</span> <span class="hljs-built_in">bigint</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x76EE;&#x6807;&#x7528;&#x6237;ID&apos;</span>,
  <span class="hljs-string">`relation`</span> tinyint(<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">&apos;0&apos;</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x5173;&#x7CFB;&#xFF0C;0-&#x53D6;&#x6D88;&#xFF0C;1-&#x5173;&#x6CE8;&#xFF0C;2-&#x62C9;&#x9ED1;&apos;</span>,
  <span class="hljs-string">`create_time`</span> datetime <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&apos;</span>,
  <span class="hljs-string">`update_time`</span> datetime <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">ON</span> <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">CURRENT_TIMESTAMP</span> <span class="hljs-keyword">COMMENT</span> <span class="hljs-string">&apos;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&apos;</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`relation_id`</span>),
  <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">KEY</span> <span class="hljs-string">`user_target`</span> (<span class="hljs-string">`user_id`</span>, <span class="hljs-string">`target_user_id`</span>)
) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8 <span class="hljs-keyword">COMMENT</span>=<span class="hljs-string">&apos;&#x7528;&#x6237;&#x5173;&#x7CFB;&#x8868;&apos;</span>;</span>
</code></pre>
<p>&#x9996;&#x5148;&#x9700;&#x8981;&#x521B;&#x5EFA;SQLAlchemy&#x5BF9;&#x8C61;:</p>
<ul>
<li><p>&#x65B9;&#x5F0F;&#x4E00;&#xFF1A;</p>
<pre><code class="lang-python">  db = SQLAlchemy(app)
</code></pre>
</li>
<li><p>&#x65B9;&#x5F0F;&#x4E8C;&#xFF1A;</p>
<pre><code class="lang-python">  db = SQLAlchemy()
  db.init_app(app)
</code></pre>
<p>  &#x6CE8;&#x610F;&#x6B64;&#x65B9;&#x5F0F;&#x5728;&#x5355;&#x72EC;&#x8FD0;&#x884C;&#x8C03;&#x8BD5;&#x65F6;&#xFF0C;&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C;&#x9700;&#x8981;&#x5728;Flask&#x7684;&#x5E94;&#x7528;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x8FDB;&#x884C;&#xFF0C;&#x5373;</p>
<pre><code class="lang-python">  <span class="hljs-keyword">with</span> app.app_context():
      User.query.all()
</code></pre>
</li>
</ul>
<p>&#x5B9A;&#x4E49;&#x6A21;&#x578B;&#x7C7B;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span><span class="hljs-params">(db.Model)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x57FA;&#x672C;&#x4FE1;&#x606F;
    &quot;&quot;&quot;</span>
    __tablename__ = <span class="hljs-string">&apos;user_basic&apos;</span>

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">STATUS</span>:</span>
        ENABLE = <span class="hljs-number">1</span>
        DISABLE = <span class="hljs-number">0</span>

    id = db.Column(<span class="hljs-string">&apos;user_id&apos;</span>, db.Integer, primary_key=<span class="hljs-keyword">True</span>, doc=<span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>)
    mobile = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x624B;&#x673A;&#x53F7;&apos;</span>)
    password = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x5BC6;&#x7801;&apos;</span>)
    name = db.Column(<span class="hljs-string">&apos;user_name&apos;</span>, db.String, doc=<span class="hljs-string">&apos;&#x6635;&#x79F0;&apos;</span>)
    profile_photo = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x5934;&#x50CF;&apos;</span>)
    last_login = db.Column(db.DateTime, doc=<span class="hljs-string">&apos;&#x6700;&#x540E;&#x767B;&#x5F55;&#x65F6;&#x95F4;&apos;</span>)
    is_media = db.Column(db.Boolean, default=<span class="hljs-keyword">False</span>, doc=<span class="hljs-string">&apos;&#x662F;&#x5426;&#x662F;&#x81EA;&#x5A92;&#x4F53;&apos;</span>)
    is_verified = db.Column(db.Boolean, default=<span class="hljs-keyword">False</span>, doc=<span class="hljs-string">&apos;&#x662F;&#x5426;&#x5B9E;&#x540D;&#x8BA4;&#x8BC1;&apos;</span>)
    introduction = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x7B80;&#x4ECB;&apos;</span>)
    certificate = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x8BA4;&#x8BC1;&apos;</span>)
    article_count = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x53D1;&#x5E16;&#x6570;&apos;</span>)
    following_count = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x5173;&#x6CE8;&#x7684;&#x4EBA;&#x6570;&apos;</span>)
    fans_count = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x88AB;&#x5173;&#x6CE8;&#x7684;&#x4EBA;&#x6570;&#xFF08;&#x7C89;&#x4E1D;&#x6570;&#xFF09;&apos;</span>)
    like_count = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x7D2F;&#x8BA1;&#x70B9;&#x8D5E;&#x4EBA;&#x6570;&apos;</span>)
    read_count = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x7D2F;&#x8BA1;&#x9605;&#x8BFB;&#x4EBA;&#x6570;&apos;</span>)

    account = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x8D26;&#x53F7;&apos;</span>)
    email = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x90AE;&#x7BB1;&apos;</span>)
    status = db.Column(db.Integer, default=<span class="hljs-number">1</span>, doc=<span class="hljs-string">&apos;&#x72B6;&#x6001;&#xFF0C;&#x662F;&#x5426;&#x53EF;&#x7528;&apos;</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserProfile</span><span class="hljs-params">(db.Model)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x8D44;&#x6599;&#x8868;
    &quot;&quot;&quot;</span>
    __tablename__ = <span class="hljs-string">&apos;user_profile&apos;</span>

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GENDER</span>:</span>
        MALE = <span class="hljs-number">0</span>
        FEMALE = <span class="hljs-number">1</span>

    id = db.Column(<span class="hljs-string">&apos;user_id&apos;</span>, db.Integer, primary_key=<span class="hljs-keyword">True</span>, doc=<span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>)
    gender = db.Column(db.Integer, default=<span class="hljs-number">0</span>, doc=<span class="hljs-string">&apos;&#x6027;&#x522B;&apos;</span>)
    birthday = db.Column(db.Date, doc=<span class="hljs-string">&apos;&#x751F;&#x65E5;&apos;</span>)
    real_name = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x771F;&#x5B9E;&#x59D3;&#x540D;&apos;</span>)
    id_number = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&apos;</span>)
    id_card_front = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x6B63;&#x9762;&apos;</span>)
    id_card_back = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x80CC;&#x9762;&apos;</span>)
    id_card_handheld = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x624B;&#x6301;&#x8EAB;&#x4EFD;&#x8BC1;&apos;</span>)
    ctime = db.Column(<span class="hljs-string">&apos;create_time&apos;</span>, db.DateTime, default=datetime.now, doc=<span class="hljs-string">&apos;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&apos;</span>)
    utime = db.Column(<span class="hljs-string">&apos;update_time&apos;</span>, db.DateTime, default=datetime.now, onupdate=datetime.now, doc=<span class="hljs-string">&apos;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&apos;</span>)
    register_media_time = db.Column(db.DateTime, doc=<span class="hljs-string">&apos;&#x6CE8;&#x518C;&#x81EA;&#x5A92;&#x4F53;&#x65F6;&#x95F4;&apos;</span>)

    area = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x5730;&#x533A;&apos;</span>)
    company = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x516C;&#x53F8;&apos;</span>)
    career = db.Column(db.String, doc=<span class="hljs-string">&apos;&#x804C;&#x4E1A;&apos;</span>)


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Relation</span><span class="hljs-params">(db.Model)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x7528;&#x6237;&#x5173;&#x7CFB;&#x8868;
    &quot;&quot;&quot;</span>
    __tablename__ = <span class="hljs-string">&apos;user_relation&apos;</span>

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RELATION</span>:</span>
        DELETE = <span class="hljs-number">0</span>
        FOLLOW = <span class="hljs-number">1</span>
        BLACKLIST = <span class="hljs-number">2</span>

    id = db.Column(<span class="hljs-string">&apos;relation_id&apos;</span>, db.Integer, primary_key=<span class="hljs-keyword">True</span>, doc=<span class="hljs-string">&apos;&#x4E3B;&#x952E;ID&apos;</span>)
    user_id = db.Column(db.Integer, doc=<span class="hljs-string">&apos;&#x7528;&#x6237;ID&apos;</span>)
    target_user_id = db.Column(db.Integer, doc=<span class="hljs-string">&apos;&#x76EE;&#x6807;&#x7528;&#x6237;ID&apos;</span>)
    relation = db.Column(db.Integer, doc=<span class="hljs-string">&apos;&#x5173;&#x7CFB;&apos;</span>)
    ctime = db.Column(<span class="hljs-string">&apos;create_time&apos;</span>, db.DateTime, default=datetime.now, doc=<span class="hljs-string">&apos;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&apos;</span>)
    utime = db.Column(<span class="hljs-string">&apos;update_time&apos;</span>, db.DateTime, default=datetime.now, onupdate=datetime.now, doc=<span class="hljs-string">&apos;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&apos;</span>)
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C02-Database/ORM.html" class="navigation navigation-prev " aria-label="Previous page: 理解ORM"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C02-Database/SQLAlchemyOperations.html" class="navigation navigation-next " aria-label="Next page: SQLAlchemy操作"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
